/* 
  for..of遍历可迭代的对象，
  for..in遍历任何对象
*/

// 可迭代性
let list: number[] = [1, 2, 3];

for (let i in list) {
  console.log(i); // return 0 1 2
}
for (let i of list) {
  console.log(i); // return 4 5 6
}

let pets = new Set(['cat', 'dog']);
pets['special'] = 'pig';

for (const pet of pets) {
  console.log(pet); // return cat dog
}
for (const pet in pets) {
  console.log(pet); // return pig
}

// 代码生成
// let numbers: number[] = [1,2,3];
// for(const num of numbers){
//   console.log(num);
// }
// 生成的代码为：
var numbers = [1,2,3];
for(var _i = 0; _i < numbers.length; _i++) {
  var num = numbers[_i];
  console.log(num);
}